<?php
namespace Lisheng\HiAdmin\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redirect;
use Lisheng\HiAdmin\Models\Student;
class HomeController{

	public function index(){

		return view('admin.index');
	}	

	public function getStudent(){

		return view('admin.content');
	}

	public function postStudent(Request $request){

		$studentInfo = $request->only(['username','age']);

		$validator = Validator::make($studentInfo,[
				'username'=>'required',	
				'age'=>'required'
			]);

		if($validator->fails())
		{
			return redirect()->back();
		}

		if(Student::create($studentInfo))
		{
			 return redirect(admin_base_path('students'))->with('status', '添加学生信息成功');
		}
	}

	public function getStudentList()
	{
		$studentlist = Student::get()->toArray();

		return view('admin.students')->with('studentlist',$studentlist);
	}
}